/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controller.Controller;
import java.util.List;
import jplay.Keyboard;
import jplay.Sprite;
import jplay.Time;

/**
 *
 * @author Marcel
 */
public class GameScreen extends Screen {

    private SpaceshipView player;
    private List<SpaceshipView> enemies;
    private Sprite points;
    private Sprite scenario;
    private boolean running;
    private Controller controller;

    GameScreen() {
        //Inicializa
        controller = new Controller(this);
        scenario = new Sprite(controller.getScenario().getTexture());
        player = new SpaceshipView(controller.getPlayer().getSprite(),
                controller.getPlayer().getPosition());
        running = true;
        while (running) {
            scenario.draw();
            player.getSprite().draw();
            getPlayerMovements();

            controller.getPlayer().getPosition();

            capturaEvento();

            getWindow().update();
        }
    }

    private void capturaEvento() {
        if (getMouse().isLeftButtonPressed()) {
            running = false;
        }
        if (getKey().keyDown(Keyboard.LEFT_KEY)) {
            controller.movement(Keyboard.LEFT_KEY);
        }
        if (getKey().keyDown(Keyboard.RIGHT_KEY)) {
            controller.movement(Keyboard.RIGHT_KEY);
        }
        if (getKey().keyDown(Keyboard.UP_KEY)) {
            controller.movement(Keyboard.UP_KEY);
        }
        if (getKey().keyDown(Keyboard.DOWN_KEY)) {
            controller.movement(Keyboard.DOWN_KEY);
        }
    }

    private void getPlayerMovements() {
        player.getSprite().x = controller.getPlayer().getPosition().getX();
        player.getSprite().y = controller.getPlayer().getPosition().getY();
    }

    public List<SpaceshipView> getEnemies() {
        return enemies;
    }

    public void setEnemies(List<SpaceshipView> enemies) {
        this.enemies = enemies;
    }

    public SpaceshipView getPlayer() {
        return player;
    }

    public void setPlayer(SpaceshipView player) {
        this.player = player;
    }

    public Sprite getPoints() {
        return points;
    }

    public void setPoints(Sprite points) {
        this.points = points;
    }
}
